/*
 * @Date: 2021-09-09 20:07:34
 * @Author: Acckno1
 * @LastEditTime: 2021-09-09 20:33:38
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 1e5 + 10;

struct School {
    string name;
    int a, b, t;
    int cnt;
    int total;

    bool operator <(const School & s1) const {
        if (total != s1.total) return total > s1.total;
        if (cnt != s1.cnt) return cnt < s1.cnt;
        return name < s1.name;
    }
}s[N];

int n;
unordered_map<string, int> mp;
int idx;


inline void solution() {
    cin >> n;
    for (int i = 0; i < n; i ++ ) {
        string id, school;
        int score;
        cin >> id >> score >> school;
        transform(school.begin(), school.end(), school.begin(), ::tolower);
        if (!mp.count(school)) {
            mp[school] = idx;
            s[idx ++ ].name = school;
        }
        if (id[0] == 'A') {
            s[mp[school]].a += score;
        } else if (id[0] == 'B') {
            s[mp[school]].b += score;
        } else {
            s[mp[school]].t += score;
        }
        s[mp[school]].cnt ++ ;
    }
    for (int i = 0; i < idx; i ++ ) {
        double t = s[i].t * 1.5 + s[i].b * 1.0 / 1.5 + s[i].a;
        s[i].total = floor(t);
    }
    sort(s, s + idx);
    int r = 1;
    
    cout << idx << endl;
    
    for (int i = 0; i < idx; i ++ ) {
        if (i == 0) {
            cout << 1 << " " << s[0].name << " " << s[0].total << " " << s[0].cnt << endl;
            continue;
        }
        if (s[i].total != s[i - 1].total) {
            cout << i + 1 << " " << s[i].name << " " << s[i].total << " " << s[i].cnt << endl;
            r = i + 1;
        }
        else
            cout << r << " " << s[i].name << " " << s[i].total << " " << s[i].cnt << endl;
    }
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}